=========================================================================== BBS: The Abacus * HST/DS * Potterville MI Date: 04-28-93 (10:02) Number: 75 From: DOUGLAS LUSHER Refer#: NONE To: QUINN TYLER JACKSON Recvd: NO Subj: FUNFIRSTPRIME Conf: (35) Quick Basi --------------------------------------------------------------------------- Here's a re-post of my message from yesterday, since the BBS I frequent chose to mangle it. Damn, I hate programs that assume they know better than I do what I want! Mr. Jackson, I was cleaning out my hard disk today and came across the routine funFirstPrime%() which I believe is part of the QB-CIMR project. I got to working on the code and made what I believe are some improvements. I have called my routine HashTableSize%(), but if you wish to make use of it, you can call it whatever you want, of course. Here is some code to compare the two routines: DECLARE FUNCTION HashTableSize% (Threshold%) DECLARE FUNCTION funFirstPrime% (Threshold%) DEFINT A-Z X% = 0: Y% = 0: Z% = 0 RANDOMIZE 12345 S! = TIMER: DO: S1! = TIMER: LOOP WHILE S! = S1! FOR Z% = 1 TO 1000 X% = 3 + INT(RND * 16380) Y% = HashTableSize%(X%) NEXT E1! = TIMER RANDOMIZE 12345 S! = TIMER: DO: S2! = TIMER: LOOP WHILE S! = S2! FOR Z% = 1 TO 1000 X% = 3 + INT(RND * 16380) Y% = funFirstPrime%(X%) NEXT E2! = TIMER T1! = E1! - S1! T2! = E2! - S2! PRINT "Time for HashTableSize:"; T1! PRINT "Time for funFirstPrime:"; T2! FUNCTION funFirstPrime (Threshold) tp30 = INT((Threshold * 1.3) + .5) IF tp30 / 2 = tp30 \ 2 THEN tp30 = tp30 + 1 END IF C = tp30 - 2 IF C < 1 THEN C = 1 END IF T2 = Threshold * 2 DO C = C + 2 FOR Z = 3 TO SQR(C) ind = -1 IF C / Z = C \ Z THEN ind = 0 EXIT FOR END IF NEXT Z IF ind THEN IF (C - 3) / 4 = INT((C - 3) / 4) OR C > T2 THEN funFirstPrime = C EXIT DO END IF END IF LOOP END FUNCTION FUNCTION HashTableSize% (Threshold%) Lo% = INT((Threshold% * 1.3) + .5) IF (Lo% AND 1) = 0 THEN Lo% = Lo% + 1 'Lo% must be odd Hi% = Threshold% * 2 FOR X% = Lo% TO 21319 STEP 2 Prime% = -1 FOR Factor% = 3 TO INT(SQR(X%)) STEP 2 IF X% MOD Factor% = 0 THEN Prime% = 0 EXIT FOR END IF NEXT IF Prime% THEN IF ((X% - 3) AND 3) = 0 OR X% > Hi% THEN HashTableSize% = X% EXIT FOR END IF END IF NEXT END FUNCTION --- TMail v1.30.4 * Origin: TC-AMS MLTBBS 2.2 - Minnetonka, MN (612)-938-4799 (1:282/7) SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1 SEEN-BY: 153/752 154/40 77 157/2 159/100 125 430 575 950 203/23 209/209 SEEN-BY: 280/1 390/1 396/1 15 397/2 2230/100 2440/5 3603/20